﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Detective.View.ConsoleViews.Base;

namespace Detective.View.ConsoleViews
{
    public class SimpleView : BaseChildView
    {
        #region Fields

        private string[] _lines;
        private string _endLeft;
        private string _endRight;

        #endregion

        #region ctor

        public SimpleView(string[] lines, string endLeft, string endRight, int width)
        {
            _lines = lines;
            _endLeft = endLeft;
            _endRight = endRight;

            Width = width;

            //TODO: Где 4 - размер границы, 2- статус, отрефакторить
            Height = _lines.Sum(p => (int)Math.Round((double)((p.Length == 0 ? 1 : p.Length) / (width - 4)) + 0.5, MidpointRounding.AwayFromZero)) + 1 + 5;
        }

        #endregion

        #region Overriden methods

        public override void RefreshView()
        {
            ClearViewAndWriteBorder();

            for (int i = 0; i < _lines.Length; i++)
            {
                WriteLine(_lines[i]);
            }

            WriteLine();

            Write(_endLeft); WriteToRight(_endRight);
        }

        public override void OnKeyDown(KeyEventArgs arg)
        {
            switch (arg.KeyCode)
            {
                case Keys.Left:
                    Parent.CloseMe(this);
                    break;
            }
        }

        #endregion
    }
}
